<template>
  <div class="container-content">
    <el-form
      ref="formRef"
      :model="formObject"
      label-width="90px"
      label-position="left"
    >
      <el-card shadow="never" class="mt20">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主类型">
              <el-select
                v-model="formObject.kingProfitLossEntity.shipperType"
                placeholder="货主类型"
                style="width: 100%"
                @change="selectshipper"
                disabled
              >
                <el-option
                  label="业务组织"
                  value="BD_OwnerOrg"
                  checked
                ></el-option>
                <el-option label="供应商组织" value="BD_Supplier"></el-option>
                <el-option label="客户组织" value="BD_Customer"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单据类型">
              <!-- <el-input v-model="formObject.kingProfitLossEntity.docTypeCode">
              </el-input> -->
              <el-select
                v-model="formObject.kingProfitLossEntity.type"
                placeholder="单据类型"
                style="width: 100%"
                disabled
              >
                <el-option label="标准盘盈单" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主">
              <el-input
                v-model="formObject.kingProfitLossEntity.shipperName"
                suffix-icon="el-icon-search"
                disabled
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日期">
              <el-date-picker
                v-model="formObject.kingProfitLossEntity.bizTime"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
                disabled
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="部门">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                disabled
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存组">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                disabled
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="仓管员">
              <el-input
                v-model="formObject.kingProfitLossEntity.keeperUserName"
                suffix-icon="el-icon-search"
                disabled
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注">
              <el-input
                v-model="formObject.kingProfitLossEntity.remarks"
                type="textarea"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
      <div class="desc-title">盘盈明细</div>
      <el-table
        :data="formObject.kingProfitLossDetailEntities"
        style="width: 100%"
        highlight-current-row
        border
        :key="flag"
      >
        <template #empty
          ><el-button plain type="primary" round @click="addNewRow" disabled
            >添加新行</el-button
          ></template
        >
        <el-table-column label="操作" width="120px">
          <template slot-scope="scope">
            <el-button
              plain
              icon="el-icon-plus"
              size="small"
              @click="handleDataAdd(scope.$index, scope.row)"
              disabled
            ></el-button>
            <el-button
              plain
              icon="el-icon-minus"
              size="small"
              @click="handleDataDelete(scope.$index, scope.row)"
              disabled
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column label="物料编码">
          <template slot-scope="scope">
            <el-input v-model="scope.row.materialCode" disabled> </el-input>
          </template>
        </el-table-column>
        <el-table-column label="物料名称">
          <template slot-scope="scope">
            <el-form-item label-width="0px" style="margin: 0">
              <el-input disabled v-model="scope.row.materialName"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="规格型号">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.model"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="单位">
          <template slot-scope="scope">
            <el-input v-model="scope.row.purchaseUnitName" disabled> </el-input>
          </template>
        </el-table-column>
        <el-table-column label="帐存数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.inventoryNum" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="盘点数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.checkNum" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="盘盈数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.profitLossNum" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="仓库">
          <template slot-scope="scope">
            <el-input v-model="scope.row.warehouseCode" disabled> </el-input>
          </template>
        </el-table-column>
        <el-table-column label="仓位">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.regionName"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="批号">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.warehouseId"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="货主">
          <template slot-scope="scope">
            <el-input v-model="scope.row.shipperId" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="备注">
          <template slot-scope="scope">
            <el-input v-model="scope.row.remarks" disabled> </el-input>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
  </div>
</template>
<script>
import {
  editKingProfitLossList,
  updataKingProfitLossList,
} from "@/api/bim/bim";
export default {
  props: ["list"],
  data() {
    return {
      listid: "",
      shipper: "",
      appendbody: true,
      title: "",
      num: 0,
      flag: false,
      count: 0,
      gridData: [],
      dialogTableVisible: false,
      formObject: {
        kingProfitLossDetailEntities: [],
        kingProfitLossEntity: {},
      },
    };
  },
  methods: {
    selectshipper(val) {
      this.shipper = val;
    },
    selectProject() {},
    handleDataAdd() {
      if (this.formObject.kingProfitLossDetailEntities == undefined) {
        this.formObject.kingProfitLossDetailEntities = [];
      }
      let obj = {
        checkNum: "",
        createBy: "",
        createTime: "",
        id: "",
        inventoryNum: "",

        materialCode: "",
        pageNo: 0,
        pageSize: 0,
        params: {},
        profitLossNum: "",
        relationId: "",
        remark: "",
        remarks: "",
        searchValue: "",
        shipperId: "",
        unit: "",
        updateBy: "",
        updateTime: "",
        warehouseCode: "",
      };
      this.formObject.kingProfitLossDetailEntities.push(obj);
    },
    addNewRow() {
      this.num = this.num + 1;
      this.handleDataAdd();
    },
    onSubmit() {
      this.formObject.kingProfitLossEntity.id = new Date();
      editKingProfitLossList(this.formObject).then((res) => {
        if (res.code === 200) {
          this.$message({
            message: "修改成功！",
            type: "success",
          });
        }
      });
    },
  },
  created() {
    this.listid = this.list;
    updataKingProfitLossList(this.listid).then((res) => {
      this.formObject = res.data;
    });
  },
};
</script>

<style lang="scss" scoped>
.divider {
  margin: 0;
}
.el-icon-search {
  margin-top: 70% !important;
}
</style>
